package edu.nf.supermarket.base;

import edu.nf.supermarket.result.ResultVO;
import org.springframework.http.HttpStatus;

/**
 * @author yjj
 * @date 2025-05-19
 */
public class BaseController {
    /**
     * 响应陈工(带数据)
     * @param data
     * @return
     * @param <T>
     */
    public <T> ResultVO<T>  success(T data){
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        vo.setData(data);
        return vo;
    }

    /**
     * 响应成功(不带数据)
     * @return
     * @param <T>
     */
    public <T> ResultVO<T>  success(){
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(HttpStatus.OK.value());
        return vo;
    }

    /**
     * 响应错误消息
     * @param code
     * @param message
     * @return
     * @param <T>
     */
    public <T> ResultVO<T> fail(int code, String message){
        ResultVO<T> vo = new ResultVO<>();
        vo.setCode(code);
        vo.setMessage(message);
        return vo;
    }
}
